<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!-- 引入 layui.css -->
    <link rel="stylesheet" href="<%=request.getContextPath()%>/component/layui/css/layui.css">
    <!-- 引入 layui.js -->
    <script src="<%=request.getContextPath()%>/component/layui/layui.js"></script>
    <title>报名结果查询</title>
    <style>
        .site-title {
            margin: 30px 0 20px;
        }
        .site-title fieldset {
            border: none;
            padding: 0;
            border-top: 2px solid #00589f;
        }
        .site-title fieldset legend {
            margin-left: 20px;
            padding: 0 10px;
            font-size: 22px;
            font-weight: 300;
        }
        .layui-inline{
            margin:10px 0px;
        }
        .layui-tab-brief>.layui-tab-title .layui-this{
            color:#00589f;
        }
        .layui-tab-brief>.layui-tab-more li.layui-this:after, .layui-tab-brief>.layui-tab-title .layui-this:after{
            border-bottom: 2px solid #00589f;
        }
        .box1{
            border:1px solid #ccc;
        }
        .backcc{
            background:#ccc;
        }
    </style>
</head>
<body>
<c:if test="${preRegList != null && preRegList.size() > 0}">
    <c:set var="isPut" value="false" />
    <c:set var="isJF" value="false" />
    <c:if test="${preLogList != null && preLogList.size() > 0}">
        <c:set var="isJF" value="true" />
        <c:if test="${preLogList[0].status == 1}">
            <h1 style="text-align: center;color: #00ff80;font-weight: bold">缴费成功（请自行下载电子发票）</h1>
            <h3 style="text-align: center;color: #444;font-weight: bold">
                <a href="javascript:void(0)" onclick="parent.location='<%=request.getContextPath()%>/common/refundPage?cardId=${preRegList[0].idCard}&graduateNo=${preRegList[0].graduateNo}'">申请退费</a>
            </h3>
        </c:if>
        <c:if test="${preLogList[0].status != 1}">
            <c:if test="${preLogList[0].status != 4}">
                <h1 style="text-align: center;color: #00ff80;font-weight: bold">报名成功，请按照提示到支付宝、微信进行缴费。（如果已经缴费成功系统会延迟更新缴费成功信息）</h1>
            </c:if>
            <c:if test="${preLogList[0].status == 3}"><h1 style="text-align: center;color: #F00;font-weight: bold">由于您较长时间未进行缴费，已将您的缴费取消。</h1></c:if>
            <c:if test="${preLogList[0].status == 4}"><h1 style="text-align: center;color: #F00;font-weight: bold">退费成功。</h1></c:if>
        </c:if>
    </c:if>
    <c:if test="${preLogList == null || preLogList.size() == 0}">
        <c:set var="isPut" value="true" />
        <h1 style="text-align: center;font-weight: bold">提交报名成功，等待审核，请及时关注报名信息。</h1>
    </c:if>

    <h1 style="display: none;color: #F00;" id="changeMajor">该专业已满额，请转其他专业</h1>
<div class="layui-row" style="margin-top: 10px">
    <div class="layui-col-md-offset4 layui-col-md4 box1" >

    <form class="layui-form" style="margin-right: 10px" action="<%=request.getContextPath()%>/BmRegistionServlet" method="post" id="showForm" enctype = "multipart/form-data">
        <div class="layui-row site-title">
            <fieldset>
                <legend><a name="size">报名信息</a></legend>
            </fieldset>
        </div>

        <div class="layui-row">
            <div class="layui-row site-title">
                <label class="layui-form-label">
                    姓名</label>
                <div class="layui-input-block">
                    <input type="text"  autocomplete="off" placeholder="请输入姓名" value="${preRegList[0].name}" disabled class="layui-input backcc">
                </div>
            </div>
            <div class="layui-row site-title">
                <label class="layui-form-label">
                    报名序号</label>
                <div class="layui-input-block">
                    <input type="text" lay-verify="required"  autocomplete="off" placeholder="请输入姓名" value="${preRegList[0].graduateNo}" disabled class="layui-input backcc">
                </div>
            </div>
            <div class="layui-row site-title">
                <label class="layui-form-label">
                    报名学校</label>
                <div class="layui-input-block">
                    <input type="text"  autocomplete="off" placeholder="请输入姓名" value="${preRegList[0].schoolName}" disabled class="layui-input backcc">
                </div>

            </div>
            <div class="layui-row site-title">
                <label class="layui-form-label">
                    层级</label>
                <div class="layui-input-block">
                    <input type="text"  autocomplete="off" placeholder="请输入姓名" value="${preRegList[0].levelName}" disabled class="layui-input backcc">
                </div>
            </div>
            <div class="layui-row site-title">
                <label class="layui-form-label">
                    专业</label>
                <div class="layui-input-block">
                    <input type="text"  autocomplete="off" placeholder="请输入姓名" value="${preRegList[0].majorName}" disabled class="layui-input backcc">
                </div>
            </div>
        </div>

        <c:if test="${isPut == true}">
            <input type="hidden" name="idCard" value="${preRegList[0].idCard}">
            <div class="layui-row" style="margin-left:10px">
                <div class="layui-col-md6 layui-col-md-offset3" style="margin-bottom: 20px;">
                    <button type="button" id="qrxgxx" class="layui-btn layui-btn-radius layui-btn-fluid layui-btn-normal">修改报名信息</button>
                </div>
                    <%--<div class="layui-col-md2">&nbsp;</div>--%>
                    <%--<div class="layui-col-md6" style="padding-right: 15px;">--%>
                    <%--<button type="reset" class="layui-btn layui-btn-radius layui-btn-fluid layui-btn-primary">重新填写</button>--%>
                    <%--</div>--%>
            </div>
        </c:if>
    </form>


    <form class="layui-form" action="<%=request.getContextPath()%>/BmRegistionServlet" method="post" id="ajaxForm" style="display: none" enctype = "multipart/form-data">
        <div class="layui-row site-title">
            <fieldset>
                <legend><a name="size">报名信息</a></legend>
            </fieldset>
        </div>

        <div class="layui-row">
            <div class="layui-row site-title">
                <label class="layui-form-label">
                    姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required"  autocomplete="off" placeholder="请输入姓名" value="${preRegList[0].name}" disabled class="layui-input">
                </div>
            </div>
            <div class="layui-row site-title">
                <label class="layui-form-label">
                    报名序号</label>
                <div class="layui-input-block">
                    <input type="text" name="graduateNo" lay-verify="required"  autocomplete="off" placeholder="请输入姓名" value="${preRegList[0].graduateNo}" disabled class="layui-input">
                </div>
            </div>
            <div class="layui-row site-title">
                <label class="layui-form-label">
                    报名学校</label>
                <div class="layui-input-block">
                    <select id="schoolId" name="schoolId" lay-filter="schoolId" lay-verify="required" required <c:if test="${isPut == false}">disabled</c:if> >
                        <option value="1" <c:if test="${preRegList[0].schoolId == 1}">selected</c:if>>江西赣州技师学院</option>
                        <option value="2" <c:if test="${preRegList[0].schoolId == 2}">selected</c:if>>赣州农业学校</option>
                    </select>
                </div>

            </div>
            <div class="layui-row site-title">
                <label class="layui-form-label">
                    层级</label>
                <div class="layui-input-block">
                    <select id="levelId" name="levelId" lay-filter="levelId" lay-verify="required" required <c:if test="${isPut == false}">disabled</c:if>>
                    </select>
                </div>
            </div>
            <div class="layui-row site-title">
                <label class="layui-form-label">
                    专业</label>
                <div class="layui-input-block">
                    <select id="majorId" name="majorId" lay-filter="majorId" lay-verify="required" required <c:if test="${isPut == false}">disabled</c:if>></select>
                </div>
            </div>
        </div>

        <c:if test="${isPut == true}">
            <input type="hidden" name="idCard" value="${preRegList[0].idCard}">
            <div class="layui-row">
                <div class="layui-col-md6 layui-col-md-offset3" style="margin-bottom: 20px;">
                    <button lay-submit lay-filter="*" class="layui-btn layui-btn-radius layui-btn-fluid layui-btn-normal">确认修改</button>
                </div>
                    <%--<div class="layui-col-md2">&nbsp;</div>--%>
                    <%--<div class="layui-col-md6" style="padding-right: 15px;">--%>
                    <%--<button type="reset" class="layui-btn layui-btn-radius layui-btn-fluid layui-btn-primary">重新填写</button>--%>
                    <%--</div>--%>
            </div>
        </c:if>


    </form>
    </div>
</div>
</c:if>

<c:if test="${preRegList == null || preRegList.size() == 0}">
    <h1 style="text-align: center;color: red;font-weight: bold">没有找到该学生信息</h1>
</c:if>

<script>
    layui.use(['form', 'jquery','layer'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let layer = layui.layer;

        let minScor = 0;

        $("#qrxgxx").click(function(){
            $("#ajaxForm").show();
            $("#showForm").hide();
        })

        // 初始化层级
        window.initLevel = function(schoolId){
            $.ajax({
                url: '<%=request.getContextPath()%>/common/queryLevelBySchoolId',
                dataType: 'json',
                data:{schoolId:schoolId},
                type: 'get',
                success: function (result) {
                    var inHtml = "<option>请选择</option>";
                    for(var i = 0;i < result.length; i++){
                        if(result[i].id == ${preRegList[0].levelId}){
                            inHtml = inHtml+"<option value='"+result[i].id+"' selected>"+result[i].levelName+"</option>"
                        }else{
                            inHtml = inHtml+"<option value='"+result[i].id+"'>"+result[i].levelName+"</option>"
                        }
                    }
                    $("#levelId").html(inHtml);
                    form.render('select'); //刷新select选择框渲染
                }
            })
        }

        // 初始化专业
        window.initMajor = function(levelId){


            $.ajax({
                url: '<%=request.getContextPath()%>/common/queryMajorByLevelId',
                dataType: 'json',
                data:{levelId:levelId},
                type: 'get',
                success: function (result) {
                    majorList = result;
                    var isFull = true;
                    var inHtml = "<option>请选择</option>";
                    for(var i = 0;i < result.length; i++){
                        // inHtml = inHtml+"<option value='"+result[i].id+"'>"+result[i].majorName+"</option>"

                        if(result[i].id == ${preRegList[0].majorId}){
                            inHtml = inHtml+"<option value='"+result[i].id+"' selected>"+result[i].majorName+"</option>"
                            minScor = result[i].minScore
                            isFull=false;
                        }else{
                            inHtml = inHtml+"<option value='"+result[i].id+"'>"+result[i].majorName+"</option>"
                        }
                    }
                    $("#majorId").html(inHtml);
                    if(isFull){
                        <c:if test="${isJF == false}">
                        $("#changeMajor").show();
                        </c:if>
                    }

                    form.render('select'); //刷新select选择框渲染
                }
            })
        }

        initLevel(${preRegList[0].schoolId})
        initMajor(${preRegList[0].levelId})

        form.on('select(schoolId)', function(data){
            initLevel($("#schoolId").val())
        });

        form.on('select(levelId)', function(data){
            initMajor($("#levelId").val())
        });

        form.on('select(majorId)', function(data){
            var majorId = $("#majorId").val();
            // console.log(majorList)
            for(var i = 0; i< majorList.length;i++){
                if(majorId == majorList[i].id){
                    minScor = majorList[i].minScore;

                    if(majorList[i].bmrs > majorList[i].planNumber){
                        alert('报名人数已大于计划人数，可以报名，我们将按分数排名择优录取。');
                    }
                    break;
                }
            }
        });

        form.on('submit(*)', function (data) {
            console.log(minScor)
            if(${preRegList[0].score} < minScor){
                alert("您的考试分数不满足该专业的最低分数。");
                return false;
            }

            var ifxg = confirm('是否确认修改？')
            if(ifxg){
                let loading = layer.load()

                $("#ajaxForm").ajaxSubmit({
                    type : 'post',
                    url : "<%=request.getContextPath()%>/preRegist",
                    dataType: 'json',
                    //data:  //注意只要是写在表单里面的，都不需要加这个属性。在controller中可以根据@RequestParam String str获取到属性值。
                    contentType : "application/x-www-form-urlencoded; charset=utf-8",
                    success: function(result) {
                        alert(result.msg)
                    },
                    error: function (data)//服务器响应失败处理函数
                    {
                        alert('返回数据不对')
                    }
                });
            }
            return false;
        });

    })
</script>
</body>
</html>
